package com.freejava.usejpa.dao;

import com.freejava.usejpa.entity.Hero;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

public interface HeroDao extends JpaRepository<Hero, Integer> {
    @Override
    List<Hero> findAll();

    // sql like : select * from tm_hero where name like "%name%"
    List<Hero> getHeroByNameContaining(String name);

    // 获取最新的英雄，根据创建时间
    @Query(value = "select * from tm_heros where creatd=(select max(created) from tm_heros)", nativeQuery = true)
    Hero getLatestHero();
}
